""" -*- coding: utf-8 -*-
 @Time    : 2019/1/27 20:49
 @Author  : 木鱼
 @File    : client.py
 @Software: PyCharm
"""
from app.libs.enums import ClientTypeNum
from app.libs.error_code import Success
from app.libs.redprint import Redprint
from app.models.user import User
from app.validates.forms import ClientForm, UserEmailForm

api = Redprint('client')


@api.route('/register', methods=['POST'])
def create_client():
    form = ClientForm().validate_for_api()
    # 因为 没有switch 所以用字典 枚举类型
    promise = {
        ClientTypeNum.USER_EMAIL: __register_user_by_email
    }
    promise[form.type.data]()
    return Success()


# 直接取 验证层的form 数据
def __register_user_by_email():
    form = UserEmailForm().validate_for_api()
    if form.validate():
        User.register_by_email(form.nickname.data, form.account.data, form.secret.data)


def __register_user_by_mine():
    pass
